<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String basePath = request.getScheme() + "://" + request.getServerName()
			+ ":" + request.getServerPort() + request.getContextPath();
%>
<jsp:include page="/WEB-INF/page/auth/_header.jsp"></jsp:include>
<body>
	<jsp:include page="/WEB-INF/page/auth/header.jsp"></jsp:include>
	<div id="middle">
		<jsp:include page="/WEB-INF/page/auth/menu.jsp"></jsp:include>
		<div id="right">
		    <div id="course_clazz_totaltb">
		        <form id="course_clazz_totalForm" class="m10">
		           	 学期：<select class="form-control1" name="termId" id="termId" onchange="changeTerm(this.text)"></select>
		           	 学籍类型：<select class="form-control1" name="studyType" id="studyType" onchange="changeStudy(this.value)">
		           	 			<option value="1">初中部</option>
		           	 			<option value="2">高中部</option>
		           	 	    </select>
		                              年级：<select class="form-control1" name="gradeType" id="gradeType"></select>
			            <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-search'" onclick="queryOk('course_clazz_total')">查询</a>
			            <a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-clear'" onclick="resetForm('course_clazz_total')">重置</a>
			        	<a class="easyui-linkbutton l-btn l-btn-small" data-options="iconCls:'icon-save'" onclick="exportExcel('course_clazz_total','<%=basePath%>/sys/course/courseClazzTotal/export')">导出为EXCEL</a>
		        </form>
		    </div>
		    <table id="course_clazz_totaldg" class="easyui-datagrid">
		    </table>
		</div>
	</div>
	<jsp:include page="/WEB-INF/page/auth/_footer.jsp"/>
	<script src="<%=basePath %>/js/datagrid-helper.js" type="text/javascript"></script>
	<script type="text/javascript">
		var url = basePath + "/sys/course/courseClazzTotal";
        $(function(){
            initTermList();
        })
        function queryOk(cf){
        	var termId = $('#termId').val();
            var gradeType = $('#gradeType').val();
            if(termId && gradeType){
                $.post(url+"/getHeader",{gradeType: gradeType},function(data){
                    var txArr=data.data.split(",");
                    var zdArr=[];   
                    var txshu = txArr.length;
                    var fieldArray = [];
                    for(var i=0;i<=txshu-1;i++){
                        title=txArr[i];
                        zdArr.push({field:title,title:title})
                    }
                    $("#"+cf+"dg").datagrid({
                    		url: url + "/pageQuery",
                    		toolbar: '#'+cf+'tb',
                    		fit : true,
                    		fitColumns : true,
                    		border : true,
                    		pagination : false,
                    		idField : 'id',
                    		pageSize : config.pageSize,
                    		autoRowHeight : 140,
                    		pageList : config.pageList,
                    		nowrap : true,
                    		striped : true,
                    		singleSelect: true,
                    		rownumbers : true,
                    		collapsible: true,
            				columns: [zdArr],
            				queryParams: {
            					termId:termId,
            					gradeType:gradeType
            				}
                    });
                })
            }else{
                $.messager.alert('操作提示','请选择学期和年级。');
            }
        }
        function changeTerm(text){
        	initGradeList(text);
        	$("#gradeType").val("");
        }
        function changeStudy(v){
        	changeTerm($("#termId").find("option:selected").text());
        	initCourseList();
        }
        function initTermList(){
            $.ajax({
                url: basePath + "/termList",
                type: 'POST',
                dataType: 'json',
                error : function(data) {
                    $.messager.progress('close');
                    $.messager.alert('系统提示', data.msg, 'error');
                },
                success: function (data) {
                	var html = "";
                	for(var i in data) {
                		html += "<option value='"+data[i].id+"'>"+data[i].termName+"</option>";
                	}
                    $("#termId").html(html);
                    initGradeList(data[0].termName);
                }
            });
        }
        function initGradeList(termName) {
        	var termYear = termName.substring(0, termName.indexOf("-"))
        	$.ajax({
         		url : basePath + "/studnetGradeByTermYear",
         		type : "get",
         		dataType : "json",
         		data: {
         			termYear: termYear,
         			studyType: $("#studyType").val()
         		},
         		async : false,
         		success : function(data) {
         			var html='';
         			for(var i in data){
         		        html += "<option value='"+data[i].value+"'>"+ data[i].text +"</option>";
         		    }
         			$("#gradeType").html(html);
         			queryOk("course_clazz_total");
         		}, error:function(){
         			alert("查询年级异常");
          		}
            });
        }
        function initCourseList() {
        	$.ajax({
         		url : basePath + "/studyCourse",
         		type : "post",
         		dataType : "json",
         		data: {
         			studyType: $("#studyType").val()
         		},
         		async : false,
         		success : function(data) {
         			var html = '<option value="">请选择</option>';
         			for(var i in data){
         		        html += "<option value='"+data[i].id+"'>"+ data[i].courseNo+""+data[i].courseName +"</option>";
         		    }
         			$("#courseId").html(html);
         		}, error:function(){
         			alert("查询年级异常");
          		}
            });
        }
    </script>
</body>
</html>